Attribute VB_Name = "modSound"
Option Explicit

' This file is part of Nightowl.
'
' Nightowl is free software: you can redistribute it and/or modify
' it under the terms of the GNU General Public License as published by
' the Free Software Foundation, either version 3 of the License, or
' (at your option) any later version.

' Nightowl is distributed in the hope that it will be useful,
' but WITHOUT ANY WARRANTY; without even the implied warranty of
' MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
' GNU General Public License for more details.

' You should have received a copy of the GNU General Public License
' along with Nightowl.  If not, see <http://www.gnu.org/licenses/>.


Private Declare Function mciExecute Lib "winmm.dll" (ByVal lpstrCommand As String) As Long
Private Declare Function sndPlaySound Lib "winmm" Alias "sndPlaySoundA" _
  (ByVal lpszSoundName As String, ByVal uFlags As Long) As Long

Private Const SND_ALIAS = &H10000
Private Const SND_ALIAS_ID = &H110000
Private Const SND_APPLICATION = &H80
Private Const SND_ASYNC = &H1
Private Const SND_FILENAME = &H20000
Private Const SND_LOOP = &H8
Private Const SND_MEMORY = &H4
Private Const SND_NODEFAULT = &H2
Private Const SND_NOSTOP = &H10
Private Const SND_NOWAIT = &H2000
Private Const SND_PURGE = &H40
Private Const SND_RESOURCE = &H4004
Private Const SND_SYNC = &H0

'Added by Erion
Public SoundSupport As Boolean
Public sounds(13) As Long 'at the moment we have 14 sounds

'The sound events
Public Const SConnect = 0
Public Const SExit = 1
Public Const SLogo = 2
Public Const SJoin = 3
Public Const SKick = 4
Public Const SMOTD = 5
Public Const SPart = 6
Public Const PMSGR = 7
Public Const SError = 8
Public Const PMSGS = 9
Public Const SSignIn = 10
Public Const SSignOut = 11
Public Const SLoading = 12
Public Const SPage = 13



Public Sub PlaySoundMCI(ByVal SoundFile As String)
mciExecute "play " + SoundFile
Debug.Print "SOUND: (MCI) Playing sound " + SoundFile
End Sub

Sub PlaySound(ByVal SoundFile As String, Optional ASync As Boolean)
If modAC.Settings.UseSounds = 0 Then Exit Sub

Dim flags As Long

If ASync = True Then flags = SND_ASYNC Else flags = SND_SYNC
sndPlaySound SoundFile, flags
Debug.Print "SOUND: (API) Playing sound " + SoundFile
End Sub

Public Sub Ding()
Dim flags As Long

flags = SND_ASYNC Or SND_ALIAS
sndPlaySound "Default", flags
Debug.Print "SOUND: 'Dinging' (system default)"
End Sub


Public Sub InitSound() 'Added by Erion
If SoundInit() Then
SoundSupport = True
Else
SoundSupport = False
MsgBox lang.Messages(100), vbCritical + vbOKOnly, lang.Messages(20)
End If

End Sub


Public Sub WaitForSound(shandle As Long) 'Added by Erion

Do
DoEvents
Loop While SoundPlaying(shandle)

End Sub

Public Sub SPlay(shandle As Long, flags As Byte, Optional Waitfs As Boolean = False) 'added by Erion
If Not SoundSupport Then Exit Sub
SoundPlay shandle, flags
If Waitfs Then
WaitForSound (shandle)
End If

End Sub

Public Sub SStop(shandle As Long)
If Not SoundSupport Then Exit Sub


SoundStop (shandle)

End Sub
